﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMSABL;
using WMSABL.SY;
using WMSAML.SY;
using ElectronicWMSA.Comm.ClassFiles;

namespace ElectronicWMSA.SY
{
    public partial class LogInfoFrm : Form
    {
        public string strWhere = "";
        TSystemLogInfoBLL bll_SystemLogInfo = new TSystemLogInfoBLL();
        PublicDataSet bll_CommonPub = new PublicDataSet();
        public LogInfoFrm()
        {
            InitializeComponent();
        }
        private void LogInfoFrm_Load(object sender, EventArgs e)
        {
            strWhere = "";
            this.pageControl1.PageCurrent = 1;
            this.pageControl1.PageSize = 100;
            this.pageControl1.Bind();
            DBind_Type();
        }
        public void DBind_Type()
        {
            DataSet ds = new DataSet();
            ds = bll_CommonPub.GetDataSet("SELECT '1'[ID],[Type]   FROM [DB_WMSFIRST].[dbo].[TSystemLogInfo] GROUP BY [Type]");
            DataTable dt = ds.Tables[0];
            DataRow dr = dt.NewRow();
            dr["ID"] = "0";
            dr["Type"] = "--请选择--";
            dt.Rows.InsertAt(dr, 0);
            this.cmb_Type.DataSource = dt;
            this.cmb_Type.ValueMember = "ID";
            this.cmb_Type.DisplayMember = "Type";
        }
        /// 绑定
        private int DBindLog()
        {
            this.dataGridViewLogInfo.CurrentCell = null;
            ElectronicWMSA.Comm.Forms.MsControls.PageData pageData = new ElectronicWMSA.Comm.Forms.MsControls.PageData();
            pageData.TableName = "TSystemLogInfo";
            pageData.PrimaryKey = "ID";
            pageData.OrderStr = "ID";
            pageData.PageIndex = this.pageControl1.PageCurrent;
            pageData.PageSize = this.pageControl1.PageSize;
            pageData.QueryCondition = strWhere;
            pageData.QueryFieldName = "*";

            this.pageControl1.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.pageControl1.bindingNavigator.BindingSource = pageControl1.bindingSource;
            this.dataGridViewLogInfo.AutoGenerateColumns = false;
            this.dataGridViewLogInfo.DataSource = this.pageControl1.bindingSource;
            this.dataGridViewLogInfo.ClearSelection();
            return pageData.TotalCount;
        }


        private int pageControl1_EventPaging(ElectronicWMSA.Comm.Forms.MsControls.EventPagingArg e)
        {
            return this.DBindLog();
        }

        private void dataGridViewLogInfo_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridViewLogInfo.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridViewLogInfo.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }

        /// <summary>
        /// 查询
        /// </summary>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            strWhere = " 1=1 ";
            string userName = this.txtUserName.Text.Trim();
            string type = this.cmb_Type.Text.Trim();
            string statTime = dtpTimeStart.Value.ToString("yyyy/MM/dd " + "00:00:00");
            string EndTime = dtpTimeEnd.Value.ToString("yyyy/MM/dd " + "23:59:00");

            if (userName != "")
            {
                strWhere = " UserName LIKE '%" + userName + "%'";
            }
            if (type != "" && type != "--请选择--")
            {
                strWhere = " Type LIKE '%" + type + "%'";
            }

            if (dtpTimeStart.Checked && dtpTimeEnd.Checked)
            {
                this.strWhere += " AND [OperateDateTime] BETWEEN '" + statTime + "'  AND '" + EndTime + "'";
            }
            else if (dtpTimeStart.Checked && dtpTimeEnd.Checked == false)
            {
                this.strWhere += " AND [OperateDateTime] > '" + statTime + "'";
            }
            else if (dtpTimeStart.Checked == false && dtpTimeEnd.Checked)
            {
                this.strWhere += " AND [OperateDateTime] < '" + EndTime + "'";
            }
            this.pageControl1.Bind();
        }

        private void txtUserName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                this.btnSearch_Click(sender, e);
            }
        }
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }

        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }

        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }
    }
}
